//
// Created by jsjxsy on 2022/8/17.
//
#include <iostream>
using namespace std;
class Exception0 {
 public:
  Exception0(int i) try: a(i) {
    cout << "Exception0()" << endl;
    cout << "a=" << a << endl;
  } catch (const exception &e) {
    cout << e.what() << endl;
  }
  ~Exception0() {
    cout << "~Exception0()" << endl;
  }
 private:
  int a;

};

class Exception1 {
 public:
  ~Exception1() {
    cout << " ~Exception1()" << endl;
  }
};

class Exception2 {
 public:
  ~Exception2() {
    cout << " ~Exception2()" << endl;
  }

};

void throwException2() throw(Exception2) {
  Exception2 e;
  throw e;
}

void throwException() {
  Exception2 e;
  throw e;
}

int main() {
  try {
    Exception0 exception_0(10);
    bad_alloc e;
    throw e;
  } catch (const bad_alloc &e) {
    cout << e.what() << endl;
  }
  try {
    Exception1 exception_1;
    throw exception_1;
  } catch (const Exception1 &e) {
    cout << "catch Exception1" << endl;
  }

  try{
    throwException2();
  } catch (const Exception2 &e) {
      cout<<"throwException2() catch Exception2"<< endl;
  }

  try{
    throwException();
  } catch (const Exception2 &e) {
    cout<<"throwException() catch Exception2"<< endl;
  }


  return 0;
}